package com.dongdongshop.serviceimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbOrderItemMapper;
import com.dongdongshop.pojo.TbOrderItem;
import com.dongdongshop.pojo.TbOrderItemExample;
import com.dongdongshop.service.TbOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class TbOrderItemServiceImpl implements TbOrderItemService {
    @Autowired
    private TbOrderItemMapper tbOrderItemMapper;
    @Override
    public void insert(TbOrderItem orderItem) {
        tbOrderItemMapper.insertSelective(orderItem);
    }

    @Override
    public void update(TbOrderItem tbOrderItem) {
        TbOrderItemExample te = new TbOrderItemExample();
        TbOrderItemExample.Criteria criteria = te.createCriteria();
        criteria.andOutTradeNoEqualTo(tbOrderItem.getOutTradeNo());
        tbOrderItemMapper.updateByExampleSelective(tbOrderItem,te);
    }

    //退款后删除
    @Override
    public void deleteByOrderId(Long orderid) {
        tbOrderItemMapper.deleteByPrimaryKey(orderid);
    }

    //查询当前订单号下的商品\
    @Override
    public TbOrderItem selectByOutTradeNo(Long orderId) {
        TbOrderItemExample te = new TbOrderItemExample();
        TbOrderItemExample.Criteria criteria = te.createCriteria();
        criteria.andOrderIdEqualTo(orderId);
        List<TbOrderItem> tbOrderItems = tbOrderItemMapper.selectByExample(te);
        if (tbOrderItems.size() <= 0){
            return null;
        }
        return tbOrderItems.get(0);
    }
}
